import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import { registerMicroApps, start, setDefaultMountApp } from "qiankun";

Vue.config.productionTip = false;

new Vue({
  router,
  render: (h) => h(App),
}).$mount("#baseapp");

let globalData = {
  data: {
    auth: "wc",
    cookiekey: "123234",
  },
};

registerMicroApps(
  [
    {
      name: "react app",
      entry: "//localhost:8000/",
      container: "#sub-reactapp1",
      activeRule: genActiveRule("/reactapp1"),
    },
    {
      name: "vue app1",
      entry: "//localhost:8082/",
      container: "#sub-vueapp1",
      activeRule: genActiveRule("/vueapp1"),
      props: globalData,
    },
    {
      name: "vue app2",
      entry: "//localhost:8083/",
      container: "#sub-vueapp2",
      activeRule: genActiveRule("/vueapp2"),
      props: globalData,
    },
  ],
  {
    beforeLoad: [
      (app) => {
        console.log("before load", app);
      },
    ], // 挂载前回调
    beforeMount: [
      (app) => {
        console.log("before mount", app);
      },
    ], // 挂载后回调
    afterUnmount: [
      (app) => {
        console.log("after unload", app);
      },
    ], // 卸载后回调
  }
);

function genActiveRule(routerPrefix) {
  return (location) => location.pathname.startsWith(routerPrefix);
}

setDefaultMountApp("/vueapp1");

start();
